<?php

namespace App\Libs\Company\SheetTemplateHandler\Aggregate;

use App\Libs\Company\SheetTemplateHandler\Aggregate\AbstractTemplate;
use App\Libs\Company\SheetTemplateHandler\Manager;
use App\Models\SheetTemplate;

class Template220 extends AbstractTemplate
{
    public $dataStartRow = 2;

    public function generateAbstract()
    {
        $this->renderHeader();
        $this->output['sheets']['sheet-01']['cellData']['0']['0'] = $this->createTitleCell("日喀则市{$this->task->year}年{$this->task->key}月\r{$this->template->name}");

        $sn = 1;
        foreach ($this->task->subTasks as $subTask) {
            $handler = Manager::createReportHandler(SheetTemplate::find($this->task->sheet_template_id), $subTask);
            $data = $handler->getData();
            foreach ($data as $row) {
                $this->output['sheets']['sheet-01']['cellData'][] = [
                    ['v' => $sn++, 's' => 'CENTER'],
                    ['v' => $row[1]['v'], 's' => 'CENTER'],
                    ['v' => $row[2]['v'], 't' => 2],
                    ['v' => $row[3]['v'], 't' => 2],
                ];
            }
        }
        $this->dataEndRow = $this->dataStartRow + $sn - 2;

        $this->renderFooter();
        return $this->output;
    }
}
